package com.allqj.sfx.ddd.member.domain.entity.flow;

import com.allqj.sfx.ddd.member.domain.enums.FlowApproverTypeEnum;
import com.allqj.sfx.ddd.member.domain.enums.FlowExceptionEnum;
import com.allqj.sfx.domain.entity.BaseEntity;

import java.util.Date;
import java.util.List;

/**
 * @author sjw
 * @className FlowInstanceTask
 * @date 2022/7/21 18:47
 * @description: 审批流-流程实例任务
 */
public class FlowInstanceTask extends BaseEntity {
    private Integer id;
    // 流程定义id
    private Integer flowDefId;
    // 流程定义id
    private Integer flowTaskDefId;
    // 流程实例id
    private Integer flowInstanceId;
    // 任务节点步骤
    private Integer taskStep;
    // 流程实例id
    private Integer nextTaskId;
    // 任务节点审批角色类型
    private Integer approverType;
    // 任务节点审批角色定义json array
    private List<Integer> approverDef;
    // 状态
    private Integer status;
    // 实际审批人
    private Integer approverId;
    // 实际审批人姓名
    private String approverName;
    // 实际审批人部门
    private Integer approverDept;
    // 实际审批时间
    private Date approverTime;

    public Integer getId() {
        return id;
    }

    public void setId(Integer id) {
        this.id = id;
    }

    public Integer getFlowDefId() {
        return flowDefId;
    }

    public void setFlowDefId(Integer flowDefId) {
        this.flowDefId = flowDefId;
    }

    public Integer getFlowTaskDefId() {
        return flowTaskDefId;
    }

    public void setFlowTaskDefId(Integer flowTaskDefId) {
        this.flowTaskDefId = flowTaskDefId;
    }

    public Integer getFlowInstanceId() {
        return flowInstanceId;
    }

    public void setFlowInstanceId(Integer flowInstanceId) {
        this.flowInstanceId = flowInstanceId;
    }

    public Integer getTaskStep() {
        return taskStep;
    }

    public void setTaskStep(Integer taskStep) {
        this.taskStep = taskStep;
    }

    public Integer getNextTaskId() {
        return nextTaskId;
    }

    public void setNextTaskId(Integer nextTaskId) {
        this.nextTaskId = nextTaskId;
    }

    public Integer getApproverType() {
        return approverType;
    }

    public void setApproverType(Integer approverType) {
        this.approverType = approverType;
    }

    public List<Integer> getApproverDef() {
        return approverDef;
    }

    public void setApproverDef(List<Integer> approverDef) {
        this.approverDef = approverDef;
    }

    public Integer getStatus() {
        return status;
    }

    public void setStatus(Integer status) {
        this.status = status;
    }

    public Integer getApproverId() {
        return approverId;
    }

    public void setApproverId(Integer approverId) {
        this.approverId = approverId;
    }

    public String getApproverName() {
        return approverName;
    }

    public void setApproverName(String approverName) {
        this.approverName = approverName;
    }

    public Integer getApproverDept() {
        return approverDept;
    }

    public void setApproverDept(Integer approverDept) {
        this.approverDept = approverDept;
    }

    public Date getApproverTime() {
        return approverTime;
    }

    public void setApproverTime(Date approverTime) {
        this.approverTime = approverTime;
    }

    public void verify(FlowApprover flowApprover) {
        if (this.getApproverDef() == null || this.getApproverDef().size() == 0) return;
        // 指定审批部门
        if (FlowApproverTypeEnum.DEPT.getCode().equals(this.getApproverType())) {
            if (this.getApproverDef().stream().anyMatch(approver -> approver != null && approver.equals(flowApprover.getDeptId())))
                return;

        }
        // 指定审批人员
        if (FlowApproverTypeEnum.USER.getCode().equals(this.getApproverType())) {
            if (this.getApproverDef().stream().anyMatch(approver -> approver != null && approver.equals(flowApprover.getUserId())))
                return;
        }
        FlowExceptionEnum.FLOW_APPROVER_NO_RIGHT.throwException();
    }
}
